<template>
  <div class="talent-container">
    <div class="talent-header">
      <h1>我们的艺人</h1>
      <p>汇聚行业精英，打造明日之星</p>
    </div>

    <div class="talent-content">
      <el-tabs v-model="activeCategory" class="talent-tabs">
        <el-tab-pane label="全部艺人" name="all"></el-tab-pane>
        <el-tab-pane label="演员" name="actor"></el-tab-pane>
        <el-tab-pane label="导演" name="director"></el-tab-pane>
        <el-tab-pane label="编剧" name="writer"></el-tab-pane>
      </el-tabs>

      <div class="talent-search">
        <el-input
            v-model="searchQuery"
            placeholder="搜索艺人姓名或作品"
            clearable
            @clear="handleSearchClear"
            @keyup.enter="handleSearch"
            style="height: 40px; line-height: 40px;"
        >
          <template #prefix>
            <el-icon><Search /></el-icon>
          </template>
        </el-input>
        <el-button
            type="primary"
            @click="handleSearch"
            style="height: 40px;"
        >
          搜索
        </el-button>
      </div>

      <el-row :gutter="30" class="talent-list">
        <el-col
            v-for="(talent, index) in filteredTalents"
            :key="index"
            :xs="24" :sm="12" :md="8" :lg="6"
        >
          <div class="talent-card" @click="handleTalentDetail(talent)">
            <div class="talent-avatar">
              <img :src="talent.avatar" :alt="talent.name" />
              <div class="talent-badge" v-if="talent.isFeatured">
                <el-icon><StarFilled /></el-icon>
              </div>
            </div>
            <div class="talent-info">
              <h3>{{ talent.name }}</h3>
              <p class="talent-title">{{ talent.title }}</p>
              <div class="talent-stats">
                <span>
                  <el-icon><VideoCamera /></el-icon>
                  {{ talent.worksCount }}部作品
                </span>
                <span>
                  <el-icon><Trophy /></el-icon>
                  {{ talent.awardsCount }}个奖项
                </span>
              </div>
              <div class="talent-tags">
                <el-tag
                    v-for="(tag, i) in talent.tags"
                    :key="i"
                    size="small"
                    :type="tagTypes[i % tagTypes.length]"
                >
                  {{ tag }}
                </el-tag>
              </div>
            </div>
          </div>
        </el-col>
      </el-row>

      <div class="talent-pagination">
        <el-pagination
            background
            layout="prev, pager, next"
            :total="totalTalents"
            :page-size="pageSize"
            v-model:current-page="currentPage"
            @current-change="handlePageChange"
        />
      </div>
    </div>

    <!-- 艺人详情对话框 -->
    <el-dialog v-model="detailVisible" :title="currentTalent?.name" width="70%">
      <div class="talent-detail">
        <div class="detail-header">
          <div class="detail-avatar">
            <img :src="currentTalent?.avatar" :alt="currentTalent?.name" />
          </div>
          <div class="detail-basic">
            <h2>{{ currentTalent?.name }}</h2>
            <p class="detail-title">{{ currentTalent?.title }}</p>
            <p class="detail-bio">{{ currentTalent?.bio }}</p>
            <div class="detail-meta">
              <p><strong>出生日期：</strong>{{ currentTalent?.birthday }}</p>
              <p><strong>身高：</strong>{{ currentTalent?.height }}cm</p>
              <p><strong>代表作品：</strong>{{ currentTalent?.representativeWorks.join('、') }}</p>
            </div>
          </div>
        </div>

        <el-divider />

        <div class="detail-works">
          <h3>作品集</h3>
          <el-scrollbar>
            <div class="works-list">
              <div
                  v-for="(work, i) in currentTalent?.works"
                  :key="i"
                  class="work-item"
              >
                <img :src="work.poster" :alt="work.title" />
                <p>{{ work.title }}</p>
                <span>{{ work.year }}</span>
              </div>
            </div>
          </el-scrollbar>
        </div>

        <el-divider />

        <div class="detail-awards" v-if="currentTalent?.awards.length">
          <h3>获奖记录</h3>
          <el-timeline>
            <el-timeline-item
                v-for="(award, i) in currentTalent?.awards"
                :key="i"
                :timestamp="award.year"
            >
              <p><strong>{{ award.name }}</strong> - {{ award.work }} ({{ award.category }})</p>
            </el-timeline-item>
          </el-timeline>
        </div>
      </div>
      <template #footer>
        <el-button @click="detailVisible = false">关闭</el-button>
        <el-button type="primary" @click="handleContactTalent">商务合作</el-button>
      </template>
    </el-dialog>
  </div>
</template>

<script setup>
import { ref, computed } from 'vue'
import {
  Search,
  StarFilled,
  VideoCamera,
  Trophy
} from '@element-plus/icons-vue'

const activeCategory = ref('all')
const searchQuery = ref('')
const currentPage = ref(1)
const pageSize = 12
const detailVisible = ref(false)
const currentTalent = ref(null)

const tagTypes = ['', 'success', 'info', 'warning', 'danger']

// 模拟艺人数据
const talentsData = ref([
  {
    id: 1,
    name: '鞠婧祎',
    title: '演员/歌手',
    avatar: 'https://image.baidu.com/search/down?url=https://tva1.sinaimg.cn/large/0073tLPGly1h2e5q3j3b1j30u0160n1x.jpg',
    isFeatured: true,
    worksCount: 15,
    awardsCount: 8,
    tags: ['一线艺人', '古装女神', '歌手'],
    bio: '中国内地影视女演员、流行乐歌手，SNH48前成员，以甜美形象和扎实演技著称。',
    birthday: '1994年6月18日',
    height: 159,
    representativeWorks: ['芸汐传', '新白娘子传奇', '如意芳霏'],
    works: [
      { title: '芸汐传', year: '2018', poster: 'https://via.placeholder.com/150x200', role: '韩芸汐' },
      { title: '新白娘子传奇', year: '2019', poster: 'https://via.placeholder.com/150x200', role: '白素贞' },
      // 更多作品...
    ],
    awards: [
      { year: '2020', name: '国剧盛典', work: '新白娘子传奇', category: '年度青春演技魅力女演员' },
      // 更多奖项...
    ]
  },
  // 更多艺人数据...
])

const totalTalents = computed(() => talentsData.value.length)

const filteredTalents = computed(() => {
  let result = talentsData.value

  // 分类筛选
  if (activeCategory.value !== 'all') {
    result = result.filter(talent =>
        talent.tags.some(tag => tag.includes(activeCategory.value))
    )
  }

  // 搜索筛选
  if (searchQuery.value) {
    const query = searchQuery.value.toLowerCase()
    result = result.filter(talent =>
        talent.name.toLowerCase().includes(query) ||
        talent.representativeWorks.some(work => work.toLowerCase().includes(query))
    )
  }

  // 分页处理 (实际项目中应为API分页)
  const start = (currentPage.value - 1) * pageSize
  return result.slice(start, start + pageSize)
})

const handleSearch = () => {
  currentPage.value = 1
}

const handleSearchClear = () => {
  searchQuery.value = ''
  currentPage.value = 1
}

const handlePageChange = (page) => {
  currentPage.value = page
}

const handleTalentDetail = (talent) => {
  currentTalent.value = talent
  detailVisible.value = true
}

const handleContactTalent = () => {
  // 处理商务合作逻辑
  detailVisible.value = false
}
</script>

<style scoped>
.talent-container {
  padding: 80px 0;
  background-color: #f9f9f9;
}

.talent-header {
  text-align: center;
  margin-bottom: 60px;
}

.talent-header h1 {
  font-size: 36px;
  color: #333;
  margin-bottom: 20px;
}

.talent-header p {
  font-size: 18px;
  color: #666;
}

.talent-content {
  width: 90%;
  margin: 0 auto;
}

.talent-tabs {
  margin-bottom: 30px;
}

.talent-search {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 20px;
}

/* 或通过class更精确控制 */
.talent-search :deep(.el-input__wrapper) {
  height: 40px;
  padding: 0 15px;
}

.talent-search :deep(.el-input__inner) {
  height: 100%;
  line-height: 40px;
}

.talent-search .el-input {
  width: 250px;
}

.talent-list {
  margin-bottom: 40px;
}

.talent-card {
  background-color: white;
  border-radius: 8px;
  overflow: hidden;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  transition: all 0.3s ease;
  cursor: pointer;
  margin-bottom: 30px;
}

.talent-card:hover {
  transform: translateY(-5px);
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
}

.talent-avatar {
  position: relative;
  height: 0;
  padding-bottom: 120%;
  overflow: hidden;
}

.talent-avatar img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: all 0.3s ease;
}

.talent-card:hover .talent-avatar img {
  transform: scale(1.05);
}

.talent-badge {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  background-color: #ffc107;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
}

.talent-info {
  padding: 20px;
}

.talent-info h3 {
  font-size: 18px;
  margin-bottom: 5px;
  color: #333;
}

.talent-title {
  font-size: 14px;
  color: #666;
  margin-bottom: 15px;
}

.talent-stats {
  display: flex;
  justify-content: space-between;
  margin-bottom: 15px;
  font-size: 12px;
  color: #888;
}

.talent-stats .el-icon {
  margin-right: 5px;
}

.talent-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.talent-pagination {
  margin-top: 20px;
  text-align: center;
}

.talent-detail {
  padding: 0 20px;
}

.detail-header {
  display: flex;
  gap: 30px;
  margin-bottom: 20px;
}

.detail-avatar {
  flex: 0 0 200px;
}

.detail-avatar img {
  width: 100%;
  border-radius: 8px;
}

.detail-basic {
  flex: 1;
}

.detail-basic h2 {
  font-size: 24px;
  margin-bottom: 5px;
  color: #333;
}

.detail-title {
  font-size: 16px;
  color: #666;
  margin-bottom: 15px;
}

.detail-bio {
  font-size: 15px;
  line-height: 1.6;
  color: #555;
  margin-bottom: 20px;
}

.detail-meta p {
  font-size: 14px;
  color: #666;
  margin-bottom: 8px;
}

.detail-works h3,
.detail-awards h3 {
  font-size: 20px;
  margin-bottom: 15px;
  color: #333;
}

.works-list {
  display: flex;
  gap: 15px;
  padding: 10px 0;
}

.work-item {
  flex: 0 0 120px;
  text-align: center;
  cursor: pointer;
}

.work-item img {
  width: 100%;
  height: 160px;
  object-fit: cover;
  border-radius: 4px;
  margin-bottom: 5px;
  transition: all 0.3s ease;
}

.work-item:hover img {
  transform: scale(1.05);
}

.work-item p {
  font-size: 13px;
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.work-item span {
  font-size: 12px;
  color: #888;
}

@media (max-width: 768px) {
  .detail-header {
    flex-direction: column;
  }

  .detail-avatar {
    flex: 0 0 auto;
    margin-bottom: 20px;
  }

  .talent-card {
    margin-bottom: 20px;
  }
}
</style>